package it.koutifaris.travianmap.dal.sqlservices.mapuiservice;

import static it.koutifaris.testforclassutils.IsTestForAssert.assertIsTestFor;
import it.koutifaris.travianmap.dal.MapUIService.MapViewState;
import it.koutifaris.travianmap.dal.sqlservices.AbstractMapDbTest;
import junit.framework.Assert;

public class SqlMapUIServiceTest extends AbstractMapDbTest {

	private SqlMapUIService sqlMapUIService;

	@Override
	protected void overridableSetUp() {
		sqlMapUIService = new SqlMapUIService(getDbHelper().getWritableDatabase());
	}

	public void testPkgAndName() {
		assertIsTestFor(SqlMapUIService.class);
	}

	public void testInitialMapViewStateOnEmptyDb() {
		MapViewState viewState = sqlMapUIService.readState();
		Assert.assertTrue(viewState.equals(MapViewStateImpl.initialState()));
	}

	public void testInsertAndRead() {
		MapViewStateImpl state = new MapViewStateImpl(1, 2, 3);
		sqlMapUIService.writeState(state);
		MapViewState readState = sqlMapUIService.readState();

		Assert.assertEquals(state, readState);
	}

	public void testInsertAndReadFloat() {
		MapViewStateImpl state = new MapViewStateImpl(1, 2, 0.5f);
		sqlMapUIService.writeState(state);
		MapViewState readState = sqlMapUIService.readState();

		Assert.assertEquals(state, readState);
	}
}
